//----------------------------------------------------------------------------
// util.h
//
// utility functions for swine
//
// Copyright (C) 2011 Neil Butterworth
//----------------------------------------------------------------------------

#ifndef INC_SWINE_UTIL_H
#define INC_SWINE_UTIL_H

#include <windows.h>
#include <string>
#include <iostream>
#include <sstream>

namespace Swine {

//----------------------------------------------------------------------------

void Reply( const std::string & s );
std::string ReadLines( std::istream & is );
int IconFromName( const std::string & iname );
int ButtonsFromName( const std::string & bname );
std::string ButtonToString( int butt );
std::string TextFromCtrl( HWND parent, int ctrl );
void SetFocus( HWND parent, int id );
HWND MustGetControl( HWND parent, int id );
std::string GetListBoxSelection( HWND parent, int lbid );
std::string GetPID();
HWND GetHwndFromPid( const std::string & pid );
OPENFILENAME MakeOFS();
void SetCtrlText( HWND parent, int ctrl, const std::string & text );


//----------------------------------------------------------------------------
// Convert streamable type to string
//----------------------------------------------------------------------------

template <typename T>
std::string Str( const T & t ) {
	std::ostringstream os;
	os << t;
	return os.str();
}

//----------------------------------------------------------------------------

template <typename T>
bool ToType( const std::string & s, T & t ) {
	std::istringstream is( s );
	return (is >> t) ? true : false;
}

//----------------------------------------------------------------------------

} // namespace

#endif
